package be.idamf.flash.events
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	
	import org.flexunit.asserts.*;

	public class DispatchEventOnTest
	{
		public var dispatcher:EventDispatcher;

		public function DispatchEventOnTest()
		{
		}

		[Before]
		public function setUp():void
		{
			dispatcher = new EventDispatcher();
		}

		[After]
		public function tearDown():void
		{
			dispatcher = null;
		}

		[Test]
		public function testEventObject():void
		{
			var check:Boolean;
			
			dispatcher.addEventListener(Event.COMPLETE, completeHandler, false, 0, true);
			dispatchEventOn(dispatcher, new Event(Event.COMPLETE));
			
			function completeHandler(event:Event):void
			{
				check = true;
			}
			
			assertTrue(check);
		}

		[Test]
		public function testEventType():void
		{
			var check:Boolean;
			
			dispatcher.addEventListener(Event.COMPLETE, completeHandler, false, 0, true);
			dispatchEventOn(dispatcher, Event.COMPLETE);
			
			function completeHandler(event:Event):void
			{
				check = true;
			}
			
			assertTrue(check);
		}
		
		[Test]
		public function testNegEventObject():void
		{
			var check:Boolean;
			
			dispatcher.addEventListener(Event.COMPLETE, completeHandler, false, 0, true);
			dispatchEventOn(dispatcher, new Event(Event.CANCEL));
			
			function completeHandler(event:Event):void
			{
				check = true;
			}
			
			assertFalse(check);
		}
		
		[Test]
		public function testNegEventType():void
		{
			var check:Boolean;
			
			dispatcher.addEventListener(Event.COMPLETE, completeHandler, false, 0, true);
			dispatchEventOn(dispatcher, Event.CANCEL);
			
			function completeHandler(event:Event):void
			{
				check = true;
			}
			
			assertFalse(check);
		}
	}
}